<?php
require '../config.php';
$query =$_REQUEST['query'];
$resultset = mysql_query($query,$conexion);

if(!$resultset)
{
    mysql_close();
    echo json_encode('error en el query: ' . mysql_error());
}
elseif(!mysql_num_rows($resultset))
{
    mysql_close();
    echo json_encode('Sin resultados');
}
else
{
	?>
	
	<button type="button" class="btn btn-default" onclick="reportarpdf();" >Imprimir <span class= 'glyphicon glyphicon-print'></span>  </button>
			<?php
			echo   "<table class='table table-bordered'>";
			echo   "<tr class='success'>";
			echo   "<th>Id OT</th><th>Cliente</th><th>Id Contrato</th><th>Fecha de Creaci&oacute;n</th><th>Tipo</th><th>Procedencia</th><th>Destino</th><th>Usuario</th>";
			echo   "</tr>";
			echo   "<tbody>";
			$aux=0;
			while($row = mysql_fetch_assoc($resultset))
			{			
			if($aux==0){
					$color="#FFFFFF";
					$aux=1;
				}else{
					$color="#F9F9F9";
					$aux=0;
				}
				if($row[idcontrato]==$row[presente])
					echo   "<tr class='danger'>";
				else
					echo   "<tr bgcolor='$color'>";
						echo   "<td>$row[idorden]</td>";
						echo   "<td>$row[nomcliente]</td>";
						echo   "<td>$row[idcontrato]</td>";
						echo   "<td>".date("d M Y",strtotime($row['fechacreacion']))."</td>";
						if($row['tipo']==1)$tipo="Radio";
						if($row['tipo']==2)$tipo="Tv";
						if($row['tipo']==3)$tipo="Radio y Tv";
						echo   "<td>".$tipo."</td>";
						echo   "<td>".$row['nomprocedencia']."</td>";
						echo   "<td>".$row['nomdestino']."</td>";
						echo   "<td>".$row['nombre']." ".$row['apellido']."</td>";
								//echo "<td><button type='button' class='btn btn-link btn-xs' data-toggle='tooltip' data-placement='top' onclick='abrir($row[idorden])' title='Abrir Orden'>Abrir Orden</button></td>";
								//echo "<td><button type='button' class='btn btn-link btn-xs' data-toggle='tooltip' data-placement='top' onclick='historia($row[idorden])' title='Ver Historial de OT'>Historial</button></td>";

							
						echo   "</tr>";
				
			}
			echo   "</tbody>";
			echo   "</table>";
			mysql_close();
		
}


function _convert($content) {
	if(!mb_check_encoding($content, 'UTF-8')
	OR !($content === mb_convert_encoding(mb_convert_encoding($content, 'UTF-32', 'UTF-8' ), 'UTF-8', 'UTF-32'))) {

		$content = mb_convert_encoding($content, 'UTF-8');

		if (mb_check_encoding($content, 'UTF-8')) {
			// log('Converted to UTF-8');
		} else {
			// log('Could not converted to UTF-8');
		}
	}
	return $content;
}
?>